package com.xbs.controller.selfdriving;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.CarEntity;
import com.xbs.entity.CarModelEntity;
import com.xbs.entity.CityEntity;
import com.xbs.entity.PagesEntity;
import com.xbs.entity.TimeCombo;
import com.xbs.service.selfdriving.CarService;
import com.xbs.service.selfdriving.SelfDrivingService;

@WebServlet("/selfDriving")
public class SelfDrivingServlet extends BaseServlet {
	private HashMap<String, Object> map;
	private List<CityEntity> city;
	private SelfDrivingService sds;

	public SelfDrivingServlet() {
		map = new HashMap<>();
		sds = new SelfDrivingService();
		city = new ArrayList<CityEntity>();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取当前页
		String page = req.getParameter("page");
		//获取每页大小
		String size = req.getParameter("size");
		
		int currpage=page==null?1:Integer.parseInt(page);
		int pagesize=size==null?4:Integer.parseInt(size);

		
		//车型
		String type="";
		//价格
		Double price=0.0;
		Double price2=999999.0;
		
		//品牌
		String pin="";
		//获取从数据库中查找到的车型
		PagesEntity<CarModelEntity> pece = sds.selCarModel(type, price, price2, pin, currpage, pagesize);

		//获取从数据库查找到的城市
		city = sds.selCity();
		
		req.setAttribute("pece", pece);
		req.setAttribute("city", city);
	
		forward("/businessview/selfDriving");
			
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		redirect("selfDriving", map);
	}
}
